import { _decorator, Component, Node,Sprite,tween,Color,color,v3,Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Ring')
export class Ring extends Component {

    public inited:boolean=false;
    public sprite:Sprite=null;

    public c:Color=color(0,0,0,0);

    onLoad()
    {
        this.init();
    }

    public init()
    {
        if(this.inited)
            return;
        this.sprite=this.node.getComponent(Sprite);
        this.inited=true;
    }

    start() {

    }

    public startAnim(c:Color)
    {
        this.init();

        this.c=c;
        this.sprite.node.setScale(0.3, 0.3, 0.3);
        tween(this.sprite.node)
            .to(0.4, { scale: v3(1.5, 1.5, 1.5)}, {
                onUpdate: (target, ratio: number) => {
                    this.sprite.color = color(this.c.r, this.c.g, this.c.b, 255 * ratio);
                }
            })
            .to(0.4, { scale: v3(0.2, 0.2, 0.2)}, {
                onUpdate: (target, ratio: number) => {
                    this.sprite.color = color(this.c.r, this.c.g, this.c.b, 255 * (1-ratio));
                }
            })
            .call(()=>{
                this.destroySelf();
            })
            .union()
            .start();


    }

    public destroySelf()
    {
        this.node.removeFromParent(true);
        this.node.destroy();
    }

    update(deltaTime: number) {
        
    }
}

